﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Platform.ObjectModel
{

	/// <summary>
	/// Realiza a criação de tokens em sequência, mantendo o contador na memória do processo
	/// </summary>
	public sealed class MemorySequenceGeneratorStrategy : ITokenGeneratorStrategy
	{
		public long sequence;

		public MemorySequenceGeneratorStrategy()
			: this( 0L )
		{ }

		public MemorySequenceGeneratorStrategy( long startAt )
		{
			this.sequence = startAt;
		}

		#region ITokenGeneratorStrategy Members

		public DocumentToken Create()
		{
			long id = Interlocked.Increment( ref this.sequence );
			return DocumentToken.NewToken( id );
		}

		#endregion
	}

}
